import { getMsg } from '_api'
const state = {
  msglist: []
}

const mutations = {
  // 设置 msg
  SET_MSG: (state, msglist) => {
    state.msglist = msglist
  },
  // 删除
  DEL_MSG: (state, index) => {
    state.msglist.splice(index, 1)
  },
  // 点击改变已读状态
  CHANGE_SATE: (state, index) => {
    state.msglist[index].isread = true
  }
}

const actions = {
  getMsg ({ commit }, token) {
    return new Promise((resolve, reject) => {
      getMsg({ token }).then(res => {
        const { data } = res
        console.log(data)
        commit('SET_MSG', data.list)// 存token
        resolve()
      }).catch(error => {
        reject(error)
      })
    })
  }
}
export default {
  namespaced: true,
  state,
  mutations,
  actions
}
